<?php

namespace app\admin\controller\system;

use app\admin\extend\Response;
use app\admin\extend\View;
use app\admin\logic\system\LoginLogic;
use app\admin\middleware\Auth;
use think\App;

class BaseController extends \app\BaseController
{
	// 视图
	use View;

	// 标题
	public $title = '';

	// 中间件
	protected $middleware = [Auth::class];

	public function __construct(App $app)
	{
		parent::__construct($app);
		$this->assign('username', LoginLogic::getUsername());
		$this->assign('title', $this->title);

        $ossVisit = config('oss.visit');
        $this->assign('ali_oss_visit', $ossVisit);
	}

	public function setError($msg='失败', $code='500', $data=[]) {
		return json(Response::setError($msg, $code, $data));
	}

	public function setSuccess($data=[], $count=0, $code=0) {
		if($data instanceof \ListWithCountStruct) {
			$count = $data->getCount();
			$data = $data->getList();
		}
		return json(Response::setSuccess($data, $count, $code));
	}
}